<script setup>
import router from "../../../router/index.js";
import MyNav from "../../../components/MyNav.vue";
import MyForm from "../../../components/MyForm.vue";
import { RULE } from "../../../const/index.js";
import { reactive, ref } from "vue";
import { insertApi } from "../../../api/axios.js";

/*======================================页面常量=============================================================*/
// 路径导航
const navItems = [
  { icon: 'Cart', label: '订单管理' },
  { icon: 'Flag', label: '购物车列表', url: '/Cart' },
  { icon: 'Flag', label: '添加购物车' },
];

/*======================================添加表单=============================================================*/
// 表单项 + 表单值 + 表单规则
let items = ref([
  { label: '课程ID', prop: 'fkCourseId',required: true, width: 20 },
  { label: '用户ID', prop: 'fkUserId',required: true, type: 'title' },

]);
let data = reactive({ info: '暂无描述' });
let rules = { info: RULE.INFO };

/**
 * 添加成功后调用
 * 1. 路由到 User 页面
 */
function insertSuccess() {
  router.push('/Cart');
}
</script>

<template>
  <my-nav :items="navItems"/>
  <el-divider/>
  <el-card class="cart-insert-card" header="添加购物车">
    <my-form type="insert"
             :items="items"
             :rules="rules"
             :args="{module: 'cart'}"
             :api="insertApi"
             :params="data"
             :callback="insertSuccess"/>
  </el-card>
</template>

<style scoped lang="scss">
.cart-insert-card {
  width: 70%; // 宽度
  margin: 20px auto 0; // 外边距
}
</style>